namespace Battle.TimelineLog
{

    /// <summary>
    /// 战斗的log类，可以输出log文件，格式可以自定义，json或者自定都行，自己实现
    /// </summary>
    public class BattleLog
    {
        public BattleLogData LogData { get; }
        public BattleLog()
        {
            LogData = new BattleLogData();
        }

        public void Init()
        {

        }

        public void AddActionCell(int time, LogActionCell actionCell)
        {
            LogAction vo = null;
            int idx = GetLogActionIdx(time);
            if (idx < 0)
            {
                vo = new LogAction();
                vo.Time = time;
                int tempIdx = LogData.Actions.Count;
                for (int i = LogData.Actions.Count - 1; i >= 0; i--)
                {
                    if (LogData.Actions[i].Time < time)
                    {
                        tempIdx = i + 1;
                        break;
                    }
                }
                LogData.Actions.Insert(tempIdx, vo);
            }
            else
                vo = LogData.Actions[idx];
            vo.ActionCells.Add(actionCell);
        }
        private int GetLogActionIdx(int time)
        {
            for (int i = LogData.Actions.Count - 1; i >= 0; i--)
            {
                if (LogData.Actions[i].Time == time)
                {
                    return i;
                }
            }
            return -1;
        }
        private LogAction GetLogAction(int time)
        {
            int idx = GetLogActionIdx(time);
            if (idx > -1)
            {
                return LogData.Actions[idx];
            }
            return null;
        }

        public string ToJson()
        {
            return "";
        }
    }
}